package com.ruoyi.repairCheck.service.impl;

import com.ruoyi.repairCheck.domain.HouseRepairCheck;
import com.ruoyi.repairCheck.mapper.HouseRepairCheckMapper;
import com.ruoyi.repairCheck.service.IHouseRepairCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 维修金额审核Service业务层处理
 *
 * @author ruoyi
 * @date 2023-05-27
 */
@Service
public class HouseRepairCheckServiceImpl implements IHouseRepairCheckService {
    @Autowired
    private HouseRepairCheckMapper  houseRepairCheckMapper;

    /**
     * 查询维修金额审核
     *
     * @param checkId 维修金额审核主键
     * @return 维修金额审核
     */
    @Override
    public HouseRepairCheck selectHouseRepairCheckByCheckId(Long checkId) {
        return houseRepairCheckMapper.selectHouseRepairCheckByCheckId(checkId);
    }

    /**
     * 查询维修金额审核列表
     *
     * @param houseRepairCheck 维修金额审核
     * @return 维修金额审核
     */
    @Override
    public List<HouseRepairCheck> selectHouseRepairCheckList(HouseRepairCheck houseRepairCheck) {
        return houseRepairCheckMapper.selectHouseRepairCheckList(houseRepairCheck);
    }


    /**
     * 修改维修金额审核
     *
     * @param checkIds 维修金额审核
     * @return 结果
     */
    @Override
    public int updateHouseRepairCheckByNo(Long[] checkIds,String userName) {
        for (Long checkId : checkIds){
            HouseRepairCheck houseRepairCheckVO = new HouseRepairCheck();
            houseRepairCheckVO.setCheckSts("2");
            houseRepairCheckVO.setCheckId(checkId);
            houseRepairCheckVO.setUpdater(userName);
            houseRepairCheckMapper.updateHouseRepairCheck(houseRepairCheckVO);
        }
        return 1;
    }

    /**
     * 批量删除维修金额审核
     *
     * @param checkIds 需要删除的维修金额审核主键
     * @return 结果
     */
    @Override
    @Transactional
    public int updateHouseRepairCheckByYes(Long[] checkIds, String userName) {
        for (Long checkId : checkIds) {
            HouseRepairCheck houseRepairCheckVO = new HouseRepairCheck();
            houseRepairCheckVO.setCheckSts("1");
            houseRepairCheckVO.setCheckId(checkId);
            houseRepairCheckVO.setUpdater(userName);
            houseRepairCheckMapper.updateRepairCheckSts(houseRepairCheckVO);
            if ("1".equals(houseRepairCheckVO.getCheckSts())) {
                houseRepairCheckVO = houseRepairCheckMapper.getRepairCheckDetail(checkId);
                houseRepairCheckMapper.updateProjectMoneyForCheck(houseRepairCheckVO);
                houseRepairCheckMapper.updateRepairMoneyForCheck(houseRepairCheckVO);
            }
        }
        return 1;
    }
}
